var express =  require("express")
var app = express();
var bodyParser =require('body-parser')
var jwt = require("./jwt")
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));

// parse application/json
app.use(bodyParser.json());

app.post("/login",function(req,res){
    if(req.body && !req.get("Authorization")){
        var token = jwt.stoken(req.body.username,"jwt","5000")
        res.json({
            code:"00001",
            data:token,
            msh:"登陆成功"
        })
    }
})
app.get("/getData",function(req,res){
    let token = req.get("Authorization"); // 从Authorization中获取token
    var resu = jwt.jtoken(token,"jwt")
    res.json(resu) 
})
app.listen("3000",function(){
    console.log("3000启动成功ok")
})